#include "Modifies.h"
#include <iostream>

//debugging and output to check
//testing

using namespace std;

	//intialise the vector
	vector<vector<int>>	Modifies::stmModifiedTable = vector<vector<int>>();
	vector<vector<int>> Modifies::varModifiedTable = vector<vector<int>>();
	
	Modifies::Modifies(){
	}

	//Uses
	void Modifies::setStmModified(int stmNum, int var){
		if(stmModifiedTable.size() >= stmNum){
			stmModifiedTable.at(stmNum - 1).push_back(var);
			
			cout << "Adding stmNum: " << stmNum << " to TableIndex: " << stmNum -1 << " for Variable " << var << endl;

		}else{
			stmModifiedTable.push_back(vector<int>());
			stmModifiedTable.at(stmNum - 1).push_back(var);
			cout << "Inserting new entry " << endl;
			cout << "Adding stmNum: " << stmNum << " to TableIndex: " << stmNum -1 << " for Variable " << var << endl;
		}
	}

	//this table should look like VarTable but with diff info on 2nd column
	void Modifies::setVarModified(int var, int stmNum){
		if(varModifiedTable.size() >= var){
			varModifiedTable.at(var - 1).push_back(stmNum);
			cout << "Adding stmNum: " << stmNum << " to TableIndex: " << stmNum -1 << " for Variable " << var << endl;
		}else{
			varModifiedTable.push_back(vector<int>());
			varModifiedTable.at(var - 1).push_back(stmNum);
			cout << "Inserting new entry ";
			cout << "Adding stmNum: " << stmNum << " to TableIndex: " << stmNum -1 << " for Variable " << var << endl;
		}
	}

	vector<int> Modifies::getStmModified(int stmNum){
		if(stmModifiedTable.size() >= stmNum){
			return stmModifiedTable.at(stmNum - 1);
		}
		else return vector<int>();
	}

	vector<int> Modifies::getVarModified(int var){
		if(varModifiedTable.size() >= var){
			return varModifiedTable.at(var - 1);
		}
		else return vector<int> ();
	}

	bool Modifies::isModified (int stmNum, int var){
		if(stmModifiedTable.size() >= stmNum){
			if(find(stmModifiedTable.at(stmNum -1).begin(), stmModifiedTable.at(stmNum -1).end(), var) != stmModifiedTable.at(stmNum -1).end()){
				return true;
			}else{
				return false;
			}
		}
		else return false;
	}


